﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Diagnostics;
namespace AgentBar
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            // Register UnhandledException
            AppDomain domain = AppDomain.CurrentDomain;
            domain.UnhandledException += new UnhandledExceptionEventHandler(UnhandledException);
            
            // ２重起動防止
            if (System.Diagnostics.Process.GetProcessesByName(System.Diagnostics.Process.GetCurrentProcess().ProcessName).Length > 1)
              {
                  return;
              }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new frmAgentBar());
        }
        static void UnhandledException(object sender, UnhandledExceptionEventArgs args)
        {
            // MessageBox
            Exception ex = (Exception)args.ExceptionObject;
            string desc = ex.Message;
#if DEBUG
            System.Diagnostics.Debug.WriteLine(desc);
#else
			if(args.IsTerminating) return;
#endif
            MessageBox.Show(desc, "UnhandledException", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
    }
}
